<template>
  <div class="grid-content">
    <el-row>
      <el-col>
        <div class="search">
          <el-form :model="queryParams" ref="queryForm" label-width="70px" label-position="left" :inline="true">
            <el-form-item label="小组名称" prop="groupName">
              <el-input v-model.trim="queryParams.groupName" placeholder="请输入小组名称" clearable
                        style="width: 240px" @keyup.enter="handleQuery" />
            </el-form-item>
            <el-form-item label="小组组长" prop="groupLeader">
              <el-input v-model.trim="queryParams.groupLeader" placeholder="请输入小组组长" clearable
                        style="width: 240px" @keyup.enter="handleQuery" />
            </el-form-item>
          </el-form>
          <el-button type="primary" @click="handleQuery">查询</el-button>
        </div>
      </el-col>
    </el-row>
    <el-row>
      <div class="wrapBox" style="width: 100%;">
        <el-table v-loading="loading" :data="groupList" stripe style="width: 100%">
          <el-table-column prop="groupName" align="center" label="小组名称" show-overflow-tooltip />
          <el-table-column prop="groupLeader" align="center" label="小组组长" show-overflow-tooltip />
          <el-table-column prop="groupMember" align="center" label="小组成员" show-overflow-tooltip width="200px"/>
          <el-table-column prop="groupExpert" align="center" label="专家成员" show-overflow-tooltip width="200px"/>
          <el-table-column prop="operation" label="操作" align="center">
            <template #default="scope">
              <el-button type="text" @click="fenPei(scope.row)">分配</el-button>
            </template>
          </el-table-column>
        </el-table>
      </div>
    </el-row>
    <el-row>
      <pagination style="margin-top: 15px" v-show="total > 0" :total="total" v-model:page="queryParams.page"
                  v-model:limit="queryParams.rows" @pagination="getList" />
    </el-row>
  </div>
</template>

<script setup>
import { getGroup } from "@/api/taskmanage/group.js";
const { proxy } = getCurrentInstance();

const emits = defineEmits()
const loading = ref(false);
const total = ref(0);
const queryParams = reactive({
  page: 1,
  rows: 10,
  groupName: undefined,
  groupLeader: undefined,
  groupMember: undefined,
  groupExpert: undefined,
  groupId: undefined
});

const groupList = ref([]);
const groupObj = ref({});

/** 查询小组列表 */
function getList() {
  loading.value = true;
  getGroup(queryParams).then((response) => {
    nextTick(() => {
      groupList.value = response.data.result;
      total.value = response.data.total;
      loading.value = false;
    });
  });
}

// 分配
const fenPei = (row) => {
  groupObj.value = row;
  emits("queryGroup", groupObj.value);
};

function reset() {
  groupObj.value = {};
  proxy.resetForm("queryForm");
}
/** 搜索按钮操作 */
function handleQuery() {
  queryParams.page = 1;
  getList();
}

/** 重置按钮操作 */
function resetQuery() {
  proxy.resetForm("queryForm");
  handleQuery();
}
getList()
defineExpose({
  reset,
});
</script>

<style scoped>
.grid-content{
  width: 780px;
  margin: 0 auto;
}
.search{
  display: flex;
  justify-content: space-between;
}
</style>